package cn.appsys.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.appsys.biz.AppInfoBiz;
import cn.appsys.biz.BackendUserBiz;
import cn.appsys.pojo.AppInfo;
import cn.appsys.pojo.BackendUser;
import cn.appsys.pojo.DataDictionary;


@Controller
public class AdminController {
	
	@Autowired
	private BackendUserBiz backendUserBiz;
	
	@Autowired
	private AppInfoBiz appInfoBiz;
	
	
	
	@RequestMapping("/backendLogin")
	public String backendLogin(){
		return "backendLogin";
	}
	
	@RequestMapping(value="/rebackendLogin",method=RequestMethod.POST)
	public String reBackendLogin(Model model,String name,String password,HttpSession session){
		BackendUser user = backendUserBiz.checkBackendUser(name, password);
		if(user != null){
			session.setAttribute("admin", user);
			session.removeAttribute("user");
			return "advocate";
		}
		model.addAttribute("checkInfo", "用户名或密码输入错误！");
		return "backendLogin";
	}
	

	@RequestMapping("/updateStatusAdmin")
	public String updateVersion(Model model,Integer appId){
		model.addAttribute("app", appInfoBiz.getById(appId));
		return "updateStatus";
	}
	
	@RequestMapping("reUpdateStatusAdmin")
	public String updateStatus(Model model,Integer id,Integer valueId){
		appInfoBiz.updateStatus(id, valueId);
		return "redirect:adminAppList?appStatus=1";
	}
}
